package com.robot.mvvm.vm.work

import android.app.Application
import androidx.databinding.BaseObservable
import androidx.databinding.ObservableField
import api.UserServiceFactory
import com.robot.base.base.vm.GLBaseViewModel
import com.robot.base.common.api.AbstractViewModelSubscriber
import com.robot.base.model.PersonDetailDTOBean
import me.goldze.mvvmhabit.http.BaseResponse

class SafetyDetailViewModel(application: Application) : GLBaseViewModel(application) {

    val photo = ObservableField<String>()
    val personName = ObservableField<String>()
    val sex = ObservableField<String>()
    val age = ObservableField<String>()
    val idCard = ObservableField<String>()
    val contactPhone = ObservableField<String>()
    val education = ObservableField<String>()
    val major = ObservableField<String>()
    val email = ObservableField<String>()
    val address = ObservableField<String>()
    val certType = ObservableField<String>()
    val gmtCertExpire = ObservableField<String>()
    val certImage = ObservableField<String>()

    fun getSafetyPersonDetail(personId: String) {
        UserServiceFactory.getSafetyPersonDetail(
            mapOf(
                "personId" to personId
            )
        ).subscribe(object : AbstractViewModelSubscriber<BaseResponse<PersonDetailDTOBean>>(this) {
            override fun onNext(t: BaseResponse<PersonDetailDTOBean>) {
                photo.set(t.data.photoUrl)
                personName.set(t.data.personName)
                sex.set(
                    if (t.data.sex == "0") {
                        "女"
                    } else {
                        "男"
                    }
                )
                age.set(t.data.age)
                idCard.set(t.data.idCard)
                contactPhone.set(t.data.contactPhone)
                education.set(t.data.educationStr)
                major.set(t.data.major)
                email.set(t.data.email)
                address.set(t.data.address)
                certType.set(t.data.certTypeStr)
                gmtCertExpire.set(t.data.gmtCertExpireStr)
                certImage.set(t.data.certImageUrl)
            }
        })
    }
}